package com.ten.order.controller;

import com.ten.order.service.TOrderService;
import com.ten.order.vo.OrderVo;
import com.ten.order.vo.PayLogVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ten.common.core.entity.TOrder;
import com.ten.common.core.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ：王薪伟
 * @date ：Created in 2022/12/6 16:45
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/order/order")
@Api(tags = "订单接口类")
public class TOrderController {

    @Autowired
    private TOrderService tOrderService;


    //获取全部订单
    @ApiOperation(value = "查询全部订单并分页")
    @PostMapping("getAllOrder/{currentPage}/{pageSize}")
    public Result<IPage<TOrder>> getAllOrder(@PathVariable(required = true) Integer currentPage,
                                             @PathVariable(required = true) Integer pageSize,
                                             @RequestBody OrderVo orderVo) {
        return tOrderService.findAllOrderByPage(currentPage, pageSize, orderVo);
    }


    @ApiOperation(value = "根据订单号查询详细订单")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "订单号", name = "order_no")
            }
    )
    @PostMapping("queryOrderAndPayLog/{orderNo}")
    public Result<PayLogVo> queryOrderAndPayLog(@PathVariable String orderNo) {
        System.out.println(orderNo);
        return tOrderService.findAllOrder(orderNo);
    }

    @PostMapping("getOrderStatus/{courseId}/{memberId}")
    public Result getOrderStatus(@PathVariable String courseId ,
                                 @PathVariable String memberId){
        return tOrderService.findOrderStatus(courseId,memberId);
    }

    @ApiOperation(value = "根据订单id删除订单")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(value = "订单id", name = "id")
            }
    )
    @PostMapping("deleteOrder/{id}")
    public Result deleteOrder(@PathVariable String id){
        return tOrderService.deleteOrderById(id);
    }
}
